import { ref } from "vue"
import store from "@/store"
import { defineStore } from "pinia"
import { IGetComboData } from "@/api/combo/types/combo"
import { getComboDataApi10 } from "@/api/combo"
import { useUserStore } from "./user"
const userStore = useUserStore()
export const useComboStore = defineStore(
  "combo",
  () => {
    const comboListStore = ref<IGetComboData[]>([])
    /** 设置套餐列表 */
    const setComboList = (value: IGetComboData[]) => {
      comboListStore.value = value
    }

    const getComoboFn = async () => {
      //套餐持久化
      await getComboDataApi10({
        state: "",
        team: userStore.teamName || ""
      }).then((res: any) => {
        setComboList(res.data)
      })
    }
    return {
      comboListStore,
      setComboList,
      getComoboFn
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          storage: localStorage
          // paths: ["jobListStore", "authListStore"] //指定要长久化的字段
        }
      ]
    }
  }
)
/** 在 setup 外使用 */
export function useComboStoreHook() {
  return useComboStore(store)
}
